package webTest.myTag.NormalTag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
import java.io.IOException;

/**
 * Created by IFT8 on 2015/3/17.
 */
public class IpJSPBody implements Tag {
    private PageContext pageContext;
    @Override
    public void setPageContext(PageContext pc) {
        //Step 1
        this.pageContext=pc;
    }

    @Override
    public void setParent(Tag t) {
        //Step 2
    }

    @Override
    public Tag getParent() {
        return null;
    }

    @Override
    public int doStartTag() throws JspException {
        //Step 3
        String ip=pageContext.getRequest().getRemoteAddr();
        try {
            pageContext.getOut().print(ip);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return EVAL_BODY_INCLUDE; //执行Tag内的代码
    }

    @Override
    public int doEndTag() throws JspException {
        //Step 4
        return SKIP_PAGE; //跳过Tag外的代码
    }

    @Override
    public void release() {
        //Step 5
    }
}
